Title: SQL W3S (By-BKK) / 112 Check
Tags: Obsidian_to_Anki

Q: What does the SQL CHECK constraint do?
A: It limits the value range that can be placed in a column

Q: True or False: The CHECK constraint can only be applied to a single column.
A: False

Q: How do you use CHECK constraint when creating a table?
A: Add CHECK(condition) in the column definition in CREATE TABLE

Q: Example: What does this SQL statement ensure? CREATE TABLE Persons (Age int CHECK (Age>=18));
A: It ensures that the Age is at least 18 for each row

Q: How can CHECK constraint use multiple columns?
A: Define the CHECK with a condition that references more than one column

Q: What is the syntax to name a CHECK constraint on multiple columns?
A: CONSTRAINT constraint_name CHECK (condition)

Q: Answer first: It allows only certain values for a column.
A: What does defining a CHECK constraint on a column do?

Q: True or False: The CHECK constraint can use values of other columns in the same row.
A: True

Q: How do you add a CHECK constraint after the table is created?
A: Use ALTER TABLE table_name ADD CHECK(condition);

Q: What does this SQL do? ALTER TABLE Persons ADD CHECK (Age>=18);
A: It adds a CHECK constraint so Age must be at least 18

Q: How can you name a CHECK constraint while adding it with ALTER TABLE?
A: Use ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK(condition);

Q: What is the syntax to drop a CHECK constraint in SQL Server/Oracle/MS Access?
A: ALTER TABLE table_name DROP CONSTRAINT constraint_name;

Q: How do you drop a CHECK constraint in MySQL?
A: ALTER TABLE table_name DROP CHECK constraint_name

Q: Answer first: It limits values in certain columns based on other columns in the row.
A: What does a CHECK constraint do when defined on a table?

Q: True or False: CHECK constraint is used for linking tables by primary/foreign keys.
A: False

Q: Give an example of a multi-column CHECK constraint.
A: CHECK(Age>=18 AND City='Sandnes')

Q: What is the primary purpose of the SQL CHECK constraint?
A: To limit the value range that can be placed in a column